# Definition for a binary tree node.
from typing import Optional


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution:
    def maxDepth(self, root: Optional[TreeNode]) -> int:
        if root is None:
            return 0

        ret = 0
        line = [root]
        while line:
            ret += 1
            temp = []
            for node in line:
                if node.left:
                    temp.append(node.left)
                if node.right:
                    temp.append(node.right)
            line = temp
        return ret
